<template>
	<view class="content">
		<view class="input_box">
			<textarea placeholder="请输入您要留言的内容" class="textarea border" v-model="list.content"></textarea>
			<input type="text" class="input_box border" v-model="list.name" placeholder="请输入用户名:" />
			<button @click="Add" class="submit">提交</button>
		</view>

		<view class="list">
			<view class="item" v-for="(item, index) in listData" :key="index">
				<view class="word">
					<text class="user_name">{{ item.name }}</text>
					<text class="content">{{ item.content }}</text>
				</view>
				<text class="delete" @click="remove(item._id)">删除</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: {
					name: "",
					content: ""
				},
				listData: [{
					_id: "",
					name: "",
					content: ""
				}]
			}
		},
		onLoad() {
			this.getData()
		},
		methods: {
			Add() {
				let data=this.list
				uniCloud.callFunction({
					name:'add',
					data:data
				}).then(res=>{
					this.getData()
					this.list=[]
				})
			},
			getData() {
				uniCloud.callFunction({
					name:'get'
				}).then(res=>{
					this.listData=res.result.data
				})

			},
			remove(id) {
				let _id=id
				uniCloud.callFunction({
					name:'remove',
					data:{
						_id
					}
				}).then(res=>{
					this.getData()
					console.log(res)
				})
			}
		}
	};
</script>

<style lang="scss">
	.border {
		border-style: solid;
		border-width: 1px;
		border-color: #eeeeee;
	}

	.input {
		padding: 6rpx 8rpx;
		height: 42px;
		margin: 10rpx;
	}

	.submit {
		width: 400upx;
		margin-left: 175rpx;
		margin-top: 10px;
		margin-bottom: 20px;
	}

	.delete {
		background-color: #dddddd;
		color: #ffffff;
		width: 40rpx;
		line-height: 50rpx;
		height: 50rpx;
		text-align: center;
		width: 80rpx;
		font-size: 30rpx;
		border-radius: 6px;
	}

	.list {
		width: 750rpx;
	}

	.input_box {
		width: 750rpx;
		background-color: #ffffff;
		margin-bottom: 6px;
	}

	.textarea {
		width: 730rpx;
		padding: 10rpx;
		margin: 10rpx;
	}

	.item {
		@extend .border;
		border-radius: 16px;
		border-color: #eeeeee;
		padding: 4px 8px;
		margin: 5px;
		flex-direction: row;
		align-items: center;
	}

	.logo {
		width: 100rpx;
		height: 100rpx;
		border-radius: 100px;
	}

	.word {
		padding: 20rpx;
		flex: 1;
		justify-content: space-around;
	}

	.user_name {
		font-size: 28upx;
		color: #007aff;
	}

	.content {
		font-size: 38upx;
		color: #666666;
	}
</style>
